package com.gofaraway.service.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author ChenPeng
 * @Date 2024/3/25 22:29
 */
public class FutureTaskDemo {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new MyThread());

        Thread thread = new Thread(futureTask, "t1");//开启一个异步线程

        thread.start();

        futureTask.get();//有返回hello Callable
    }
}

class MyThread implements Callable<String> {


    @Override
    public String call() throws Exception {
        System.out.println("--------------come in");

        return "hello Callable";
    }
}
